<template>
  <div>
    <!-- 头部 -->
    <div class="dark-top">
      <a @click="goback" class="page-back"><div></div></a>
      <div class="page-title">
        <font style="vertical-align: inherit;">跑腿配送</font>
      </div>
    </div>
    <!-- 与头部高度一致 -->
    <div style="height: 4.125rem;"></div>
    <!-- 列表 -->
    <div
      class="dark-body"
      v-infinite-scroll="loadMore"
      infinite-scroll-disabled="busy"
      infinite-scroll-distance="10"
      infinite-scroll-immediate-check="true"
    >
      <div class="single-bj"></div>
      <div class="single-top">
        <div class="single-cont">正在配送订单量：{{ totalNumber }} 件</div>
      </div>
      <!-- 与固定头高加margin -->
      <div style="height: 4.0625rem"></div>
      <!-- 列表内容 -->
      <div
        class="single-list"
        v-for="item in shipping"
        :key="item.id"
        @click="goShippingInfo(item.oid)"
      >
        <div class="list-left box_left">
          <div class="list-order">
            订单编号<span>{{ item.number }}</span>
          </div>
          <div class="list-order">
            创建时间<span>{{ item.create_time }}</span>
          </div>
          <div class="list-order-name">收货人：{{ item.username }}</div>
          <div class="list-order-name">收货地址：{{ item.user_site }}</div>
          <div class="list-order-name">收货人电话：{{ item.user_tel }}</div>
        </div>
        <div class="list-right box_right signle-cole" v-if="item.status != 2">
          <div class="list-cont">正在配送</div>
        </div>
        <div class="list-right box_right signle-end" v-else>
          <div class="list-cont">配送完成</div>
        </div>
      </div>
      <p v-show="infiniteMsgShow" class="tips">加载下一页</p>
      <p v-show="!infiniteMsgShow" class="tips">没有更多数据</p>
    </div>
  </div>
</template>

<script>
import { Indicator } from "mint-ui";
import { Toast } from "mint-ui";
export default {
  data() {
    return {
      busy: true,
      page: 0,
      limit: 10,
      contentShow: "",
      infiniteMsgShow: true,
      shipping: [],
      totalNumber: 0
    };
  },
  created() {
    this.loadMore();
  },
  methods: {
    goback() {
      this.$router.go(-1);
    },
    //到 配送详情页
    goShippingInfo(oid) {
      localStorage.ps_oid = oid;
      this.$router.push({
        name: "ShippingDetails",
        params: { ps_oid: oid }
      });
    },
    // 当属性滚动的时候  加载  滚动加载
    loadMore() {
      this.busy = true; // 将无限滚动给禁用
      setTimeout(() => {
        //发送请求有时间间隔第一个滚动时间结束后才发送第二个请求
        this.page++; //滚动之后加载第二页
        this.selectShippingList();
      }, 500);
    },
    //获取配送列表
    selectShippingList() {
      Indicator.open({ spinnerType: "fading-circle" });
      let me = this;
      this.$axios
        .post(
          "/api/home/shippingUpdate",
          { uid: localStorage.uid, page: this.page, limit: this.limit },
          { emulateJSON: true }
        )
        .then(kun => {
          console.log(kun);
          Indicator.close();

          me.totalNumber = kun.total;

          let listTotal = kun.total;
          if (listTotal > 0) {
            me.contentShow = true;
          } else {
            me.contentShow = false;
          }
          me.shipping = me.shipping.concat(kun.data);
          let DownloadTotal = me.page * me.limit;
          let total = kun.total;

          if (DownloadTotal > total) {
            me.busy = true; // 将无限滚动关闭
            me.page = 0; // 页数变为0
            me.infiniteMsgShow = false; // 切换底部提示信息
          } else {
            me.busy = false; // 当还有多余的数据时，将无限滚动给打开 ，就是可以继续滚动去请求后台
            me.infiniteMsgShow = true;
          }

          if (kun.code != 200) {
            Toast(kun.msg);
          }
        })
        .catch(function(error) {
          console.log(error);
        });
    }
  }
};
</script>

<style lang="scss" scoped>
//下拉 没有数据
.empty {
  font-size: 0.875rem;
  color: #999999;
  text-align: center;
  margin-top: 5.25rem;
}
//下拉 加载下一页
.tips {
  font-size: 0.875rem;
  color: #999999;
  text-align: center;
  margin: 1.25rem 0;
}
.box_left {
  float: left;
}
.box_right {
  float: right;
}
//头部
.dark-top {
  width: 100%;
  height: 4.125rem;
  color: #1a1a1a;
  position: fixed;
  z-index: 999;

  /* 设置渐变 */
  background: rgb(255, 0, 0); /* Old browsers */
  background: -moz-linear-gradient(
    to right bottom,
    rgb(255, 127, 95) 10%,
    rgb(229, 39, 77) 70%
  ); /* FF3.6-15 */
  background: -webkit-linear-gradient(
    to right bottom,
    rgb(255, 127, 95) 10%,
    rgb(229, 39, 77) 70%
  ); /* Chrome10-25,Safari5.1-6 */
  background: linear-gradient(
    to right bottom,
    rgb(255, 127, 95) 10%,
    rgb(229, 39, 77) 70%
  ); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
  filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ff0000', endColorstr='#ffffff',GradientType=0 ); /* IE6-9 */

  .page-back {
    width: 0.5625rem;
    height: 0.9375rem;
    text-decoration: none;
    color: #1a1a1a;
    display: inline-block;
    position: absolute;
    left: 0.9375rem;
    top: 2.0625rem;

    :first-child {
      width: 100%;
      height: 100%;
      background-image: url(../../assets/login/return-white.png);
      background-repeat: no-repeat;
      background-size: contain;
      background-position: center;
      overflow: hidden;
    }
  }

  .page-title {
    font-size: 1.125rem;
    color: #ffffff;
    display: inline-block;
    position: absolute;
    left: 50%;
    top: 1.875rem;
    -ms-transform: translateX(-50%) translateY(0); /* IE 9 */
    -moz-transform: translateX(-50%) translateY(0); /* Firefox */
    -webkit-transform: translateX(-50%) translateY(0); /* Safari 和 Chrome */
    -o-transform: translateX(-50%) translateY(0); /* Opera */
  }
}

//列表
.dark-body {
  width: 21.5625rem;
  margin: 0 auto;

  .single-bj {
    width: 21.5625rem;
    height: 0.9375rem;
    position: fixed;
    z-index: 999;
    background: white;
  }
  .single-top {
    margin-top: 0.9375rem;
    width: 21.5625rem;
    height: 3.125rem;
    background-image: url(../../assets/shop/single.png);
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center;
    overflow: hidden;
    position: fixed;
    z-index: 999;

    .single-cont {
      line-height: 3.125rem;
      text-align: center;
      font-size: 0.9375rem;
      color: #ffffff;
    }
  }
  // 列表内容
  .single-list {
    margin-top: 0.625rem;

    width: 100%;
    height: 7.5rem;
    background: #ffffff;
    box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.05);
    border-radius: 0.3125rem;

    .list-left {
      width: 17.5rem;
      margin-left: 0.625rem;
      overflow: hidden;

      .list-order {
        font-size: 0.875rem;
        color: #333333;
        margin-top: 0.375rem;
        span {
          margin-left: 1.25rem;
        }
      }
      .list-order-name {
        font-size: 0.75rem;
        color: #9a9a9a;
        margin-top: 0.3125rem;
      }
    }

    .list-right {
      width: 3.0625rem;
      height: 100%;

      border-radius: 0 0.3125rem 0.3125rem 0;
      font-size: 0.9375rem;
      color: #ffffff;

      .list-cont {
        width: 0.9375rem;
        margin: 0 auto;
        position: relative;
        top: 50%;
        left: 0;
        -ms-transform: translateX(0) translateY(-50%); /* IE 9 */
        -moz-transform: translateX(0) translateY(-50%); /* Firefox */
        -webkit-transform: translateX(0) translateY(-50%); /* Safari 和 Chrome */
        -o-transform: translateX(0) translateY(-50%); /* Opera */
      }
    }
    // 正在配送
    .signle-cole {
      background: linear-gradient(-10deg, #e5274d, #ff7f5f);
    }
    // 配送完成
    .signle-end {
      background: linear-gradient(-10deg, #f399ab, #ffc3b4);
    }
  }
}
</style>
